# https://www.bilibili.com/video/BV1T5411i7Gg/?spm_id_from=333.1365.list.card_archive.click&vd_source=ad559e41b561d48861f70d0187e51e02
from utils.log import Log


# 巴什博弈(Bash Game)
# 一共有n颗石子，两个人轮流拿，每次可以拿1~m颗石子拿到最后一颗石子的人获胜，根据n、m返回谁赢
class Bash(Log):
    def __init__(self, n, m=5):
        super(Bash, self).__init__()
        self.n = n
        self.m = m

    def who(self):
        return '先手' if self.n % (self.m + 1) else '后手'

    def who_win(self):
        who = self.who()
        self.info(f"{self.__class__.__name__}(n={self.n}, m={self.m}) {who}赢")


# 质数次方版取石子(巴什博弈扩展)
# -共有n颗石子，两个人轮流拿每一轮当前选手可以拿 p的k次方颗石子当前选手可以随意决定p和k，
# 但要保证p是质数、k是自然数拿到最后一颗石子的人获胜根据石子数返回谁赢
class BashExtend(Bash):
    def __init__(self, n):
        super(BashExtend, self).__init__(n)

    def who_win(self):
        who = self.who()
        self.info(f"{self.__class__.__name__}(n={self.n}) {who}赢")


if __name__ == '__main__':
    Bash(75, 6).who_win()
    BashExtend(198).who_win()
